package com.ruoyi.web.controller.system;

import com.mysql.cj.xdevapi.Table;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.Debt;
import com.ruoyi.system.service.DebtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/system/debt")
@RestController
public class DebtController extends BaseController {

    @Autowired
    private DebtService debtService;

    @PostMapping("/addDebt")
    public AjaxResult createDebt(@RequestBody Debt debt){
        return toAjax(debtService.createDebt(debt));
    }

    @PutMapping("/removeStatus")
    public AjaxResult removeDebt(@RequestBody Debt debt){
        return toAjax(debtService.removeStatusDebt(debt));
    }

    @PostMapping("/updateDebt")
    public AjaxResult updateDebt(@RequestBody Debt debt){
        return toAjax(debtService.updateDebt(debt));
    }

    @GetMapping("/getDebt/{id}")
    public AjaxResult getDebtId(@PathVariable Integer id){
        AjaxResult ajax = AjaxResult.success();
        Debt debts = debtService.getDebtId(id);
        ajax.put(AjaxResult.DATA_TAG,debts);
        return ajax;
    }

    @GetMapping("search")
    public TableDataInfo searchDebtList(Debt debt){
        startPage();
        List<Debt> debts = debtService.searchDebt(debt);
        return getDataTable(debts);
    }

    @PutMapping("/payee")
    public AjaxResult payeeDebt(@RequestBody Debt debt){
        return toAjax(debtService.payeeDebt(debt));
    }

    @GetMapping("/list")
    public TableDataInfo selectDebtList(Debt debt){
        startPage();
        List<Debt> debts = debtService.selectDebtList(debt);
        return getDataTable(debts);
    }
}
